package 数组.easy;

/**
 * @author Lw中
 * @date 2020/8/7 12:27
 */
public class YiYiBaSi {

    public static int distanceBetweenBusStops(int[] distance, int start, int destination) {
        int sum = 0;
        for (int i = 0; i < distance.length; i++) {
            // 计算总路程
            sum+=distance[i];
        }
        int sum1 = 0;
        if (start < destination) {
            for (int i = start; i < destination; i++) {
                sum1+= distance[i];
            }
        } else {
            for (int i = destination; i < start; i++) {
                sum1+= distance[i];
            }
        }
        return Math.min(sum1, sum - sum1);
    }

    public static void main(String[] args) {
        int[] arr = {1,2,3,4};
        int i = distanceBetweenBusStops(arr, 0, 3);
        System.out.println(i);
    }

}
